<template>
    <div>
        <h1>科室信息</h1>
        <a href="/AddKS">新增科室信息</a>
        <br>
        <a href="https://localhost:7292/api/Deparment/daochu">导出数据</a>
        <br>
        科室名称:
        <input type="text" v-model="tiaoj.DMname">
        创建日期:
        <input type="date" v-model="tiaoj.Dt1">-
        <input type="date" v-model="tiaoj.Dt2">
        <input type="button" value="查询" class="btn btn-success" @click="xians()">
        <input type="button" value="重置" class="btn btn-success" @click="choz()">
        <table class="table">
            <thead>
                <tr>
                    <td>科室名称</td>
                    <td>科室人数</td>
                    <td>科室描述</td>
                    <td>创建日期</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="d in data">
                    <td>{{d.DMname}}</td>
                    <td>{{d.DMnum}}</td>
                    <td>{{d.DMms}}</td>
                    <td>{{moment(d.DMtimes).format("YYYY年MM月DD日")}}</td>
                    <td>
                        <input type="button" value="删除" class="btn btn-success" @click="shanc(d.DMid)">
                        <input type="button" value="编辑" class="btn btn-success" @click="bianj(d.DMid)">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import moment from 'moment';
import { onMounted, ref } from 'vue';
import { useRouter } from 'vue-router';
const router = useRouter();

onMounted(() => {
    xians();
});
const tiaoj = ref({
    DMname:"",
    Dt1:null,
    Dt2:null
})
const data = ref([
    {
    "DMid": 0,
    "DMname": "",
    "DMnum": 0,
    "DMms": "",
    "DMtimes": "2025-05-19T01:57:23.903",
    "IsDel": 0
  }
])
///////显示///////////
const xians = ()=>{
    axios.get("https://localhost:7292/api/Deparment/ShowKS",{params:tiaoj.value}).then(res=>{
        data.value=res.data
    })
}
///////重置///////////
const choz = ()=>{
    tiaoj.value.DMname="";
    tiaoj.value.Dt1=null;
    tiaoj.value.Dt2=null;
}
///////删除/////////
const shanc=(a:any)=>{
    if(!confirm("你确定要删除吗?"))
    {
        return;
    }
    axios.get("https://localhost:7292/api/Deparment/RemoveKS",{params:{id:a}}).then(res=>{
        if(res.data==1)
        {
            alert("删除成功");
            xians();
        }
        else
        {
            alert("删除失败");
        }
    })
}
///////编辑//////////
const bianj = (a:any)=>{
    router.push({path:'/UptKs',query:{id:a}})
}
</script>

<style scoped>

</style>